package com.penfei.springrun.controller

import com.penfei.springrun.Service.UserService
import com.penfei.springrun.model.UserInfoTestKt
import com.penfei.springrun.result.ResponseResult
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.ResponseBody

@Controller
class UserController {
    @Autowired
    var userService: UserService? = null

    @RequestMapping(value = ["/index"])
    fun index(model: Model): String {
        val user = UserInfoTestKt("张三", 15, "法外狂徒")
        model.addAttribute("user", user)
        model.addAttribute("num", "153")
        return "index"
    }

    @RequestMapping(value = ["/getUserList"], method = [RequestMethod.GET])
    @ResponseBody
    fun getUserList(): ResponseResult {
        val list = ArrayList<UserInfoTestKt>()
        list.add(UserInfoTestKt("张三", 15, "法外狂徒"))
        list.add(UserInfoTestKt("李四", 16, "狂飙"))
        return ResponseResult.success(list)
    }
}